package cs4280.ass2.persistence;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.apache.log4j.Logger;

public abstract class BaseDao {
	private static final Logger logger = Logger.getLogger(BaseDao.class);

	protected static final String DB_URL = "jdbc:sqlserver://w2ksa.cs.cityu.edu.hk:1433;databaseName=aiad922_db";
	protected static final String DB_LOGIN = "aiad922";
	protected static final String DB_PWD = "aiad922";

	protected Connection getConnection() {
		try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			return DriverManager.getConnection(DB_URL, DB_LOGIN, DB_PWD);
		} catch (SQLException e) {
			logger.error("Fail to get connection - ", e);
		} catch (ClassNotFoundException e) {
			logger.error("Cannot get the mssql JDBC driver - ", e);
		}
		return null;
	}
	
	protected static java.sql.Timestamp toSQLDate(java.util.Date uDate){
		return new java.sql.Timestamp(uDate.getTime());
		
	}
	protected static java.util.Date toUtilDate(java.sql.Timestamp sqlDate){
		return new java.util.Date(sqlDate.getTime());
	}

}
